﻿@model PaginationModel

@{
    ViewData["Title"] = "学生列表";
}

<form asp-action="index" method="get">
    <div class="form-actions no-color">
        <p>
            请输入名称：
            <input type="text" name="SearchString" value="@ViewBag.CurrentFilter" />
            <input type="submit" value="查询" class="btn btn-outline-dark" />
            | <a asp-action="index">返回所有列表</a>
            | <a asp-action="create">添加学生</a>
        </p>
    </div>
</form>

<div class="row">
    <table class="table table-bordered table-striped">
        <thead>
            <tr>
                <th scope="col">头像</th>
                <th>
                    <a asp-action="index" asp-route-sortby="Name">名字</a>
                    <a class="pl-3" asp-action="index" asp-route-sortby="Name desc">降序</a>
                </th>
                <th>
                    <a asp-action="index" asp-route-sortby="Email">邮箱地址</a>
                    <a class="pl-3" asp-action="index" asp-route-sortby="Email desc">降序</a>
                </th>
                <th scope="col">主修科目</th>
                <th>
                    <a asp-action="index" asp-route-sortby="EnrollmentDate">入学时间</a>
                    <a class="pl-3" asp-action="index" asp-route-sortby="EnrollmentDate desc">降序</a>
                </th>
                <th scope="col">操作</th>
            </tr>
        </thead>

        <tbody>

            @foreach (var student in Model.Data)
            {
                var photoPath = "~/img/avatar/noimage.png";
                if (student.PhonePath != null)
                {
                    photoPath = "~/img/avatar/" + student.PhonePath;
                }

                <tr>
                    <td>
                        <img class="table-img img-thumbnail" src="@photoPath" asp-append-version="true" />
                    </td>

                    <th scope="row">@student.Name</th>
                    <td>@student.Email</td>
                    <td>@student.Marjor.GetDisplayName()</td>
                    <td>@student.EnrollmentDate</td>
                    <td>
                        <form method="post" asp-controller="home" asp-action="delete" asp-route-id="@student.Id">
                            <a asp-controller="home" class="btn btn-info" asp-action="Detail"
                               asp-route-id="@student.Id">查看</a>
                            <a asp-controller="home" class="btn btn-primary m-1" asp-action="edit"
                               asp-route-id="@student.Id">编辑</a>
                            <span id="confirmDeleteSpan_@student.Id" style="display:none">
                                <span>您确定要删除？</span>
                                <button type="submit" class="btn btn-danger">是</button>
                                <a href="#" class="btn btn-primary" onclick="confirmDelete('@student.Id', false)">否</a>
                            </span>
                            <span id="deleteSpan_@student.Id">
                                <a href="#" class="btn btn-danger" onclick="confirmDelete('@student.Id', true)">删除</a>
                            </span>
                        </form>
                    </td>
                </tr>
            }
        </tbody>
    </table>
    <div>
        <ul class="pagination">
            <li class="page-item @(!Model.ShowFirst ? "disabled" : "")">
                <a asp-route-CurrentPage="1" class="page-link">
                    首页
                </a>
            </li>

            <li class="page-item @(!Model.ShowPrevious ? "disabled" : "")">
                <a asp-route-CurrentPage="@(Model.CurrentPage - 1)" class="page-link">
                    前一页
                </a>
            </li>

            <li class="page-item @(!Model.ShowNext ? "disabled" : "")">
                <a asp-route-CurrentPage="@(Model.CurrentPage + 1)" class="page-link">
                    后一页
                </a>
            </li>

            <li class="page-item @(!Model.ShowLast ? "disabled" : "")">
                <a asp-route-CurrentPage="@(Model.TotalPages)" class="page-link">
                    最后一页
                </a>
            </li>

            @*@for (var i = 1; i <= Model.TotalPages; i++)
                {
                    <li class="page-item @(i == Model.CurrentPage?"active":"")"></li>

                    <a asp-route-currentpage="@i" class="page-link">@i</a>
                }*@
        </ul>
    </div>
</div>

@section Scripts
{
    <script src="~/js/CustomScript.js" asp-append-version="true"></script>
}